package com.sdtele.tta.operation;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.TaskOperation;
import com.sdtele.tta.models.User;
import com.sdtele.tta.models.VoteOperation;
import com.sdtele.tta.models.VoteOption;
import com.sdtele.tta.models.VoteTask;
import com.sdtele.tta.utils.TeamUtils;

/**
 * 操作类实现：GetUser(json.operation=getUser)
 * 
 * @author XCream
 */
public class OperationAddVoteOption extends Operation {

	@Override
	public JsonResponse handle(JsonRequest jsonRequest) {
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		if (curUser!=null) {
			long voteId = jsonRequest.getJsonObject().get("voteId").getAsLong();
			String voteOptionName = jsonRequest.getJsonObject().get("voteOptionName").getAsString();
			VoteTask voteTask = Dac.getInstance().getVoteTaskbyVoteid(voteId);
			if (curUser.getId() == voteTask.getOwnerId()) {
				VoteOption Voteoption = new  VoteOption();
				Voteoption.setVoteId(voteId);
				Voteoption.setVoteOptionName(voteOptionName);
				Dac.getInstance().addVoteOption(Voteoption);
				if (Voteoption.getId()>0) {
					List<VoteOption> curVoteoption = Dac.getInstance().getVoteOption(voteId);
					jres.setStatus(0);
					jres.setMessage("添加投票选项成功");
					jres.setEntity(curVoteoption);
					return jres;
				}else {
					jres.setStatus(1);
					jres.setMessage("删除投票选项失败");
					return jres;
				}
			} else {
				jres.setStatus(1);
				jres.setMessage("您没有权限删除此投票任务");
			}
		} else {
			jres.setStatus(1);
			jres.setMessage("用户未登录");
		}
		return jres;
	}
}
